package com.ethink.warehouse.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ethink.framework.common.db.PageUtils;
import com.ethink.warehouse.api.request.*;
import com.ethink.warehouse.api.response.*;
import com.ethink.warehouse.common.mapper.ReportMateInventoryAgeMapper;
import com.ethink.warehouse.service.ReportMateInventoryAgeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 仓库库龄报表 Service接口实现
 *
 * @author default
 * @date 2023-01-29
 */
@Slf4j
@Service
public class ReportMateInventoryAgeServiceImpl implements ReportMateInventoryAgeService {

    @Autowired
    private ReportMateInventoryAgeMapper reportMateInventoryAgeMapper;

    @Override
    public Page<ReportMateInventoryAgeQueryResponse> queryReportMateInventoryAge(ReportMateInventoryAgeQueryRequest request) {
        if(StringUtils.isBlank(request.getRepDate())) {
            request.setRepDate(DateUtil.format(DateUtil.offsetDay(new Date(), -1), DatePattern.PURE_DATE_FORMAT));
        }
        request.setTableSuffix(request.getRepDate().substring(0, 6));
        return reportMateInventoryAgeMapper.queryReportMateInventoryAge(PageUtils.buildPage(request), request);
    }
}
